﻿@model Orchard.PublishLater.ViewModels.PublishLaterViewModel

@using Orchard.ContentManagement;
@using Orchard.Core.Contents;
@using Orchard.Utility.Extensions;

@{
    Style.Require("PublishLater_DatePicker");
}

@if (Authorizer.Authorize(Permissions.PublishContent, Model.ContentItem)) {
    
<fieldset class="publish-later-datetime">
    <legend>@T("Publish")</legend>
    <label class="forpicker" for="@ViewData.TemplateInfo.GetFullHtmlFieldId("ScheduledPublishDate")">@T("Date")</label>
    @Html.EditorFor(m => m.ScheduledPublishDate)
    <label class="forpicker" for="@ViewData.TemplateInfo.GetFullHtmlFieldId("ScheduledPublishTime")">@T("Time")</label>
    @Html.EditorFor(m => m.ScheduledPublishTime)
	<button type="submit" name="submit.Save" value="submit.PublishLater">@T("Publish Later")</button>
</fieldset>

using (Script.Foot()) {

    @* generates the localization script *@
    @Display(New.DatePickerLocalization())
    @Display(New.TimePickerLocalization())

<script type="text/javascript">
//<![CDATA[
    $(function () {
        
        var clearHint = function ($this) { if ($this.val() == $this.data("hint")) { $this.removeClass("hinted").val("") } };
        var resetHint = function ($this) { setTimeout(function () { if (!$this.val()) { $this.addClass("hinted").val($this.data("hint")) } }, 300) };
        @* todo: (heskew) make a plugin *@
        $("label.forpicker").each(function () {
            var $this = $(this);
            var pickerInput = $("#" + $this.attr("for"));
            if (!pickerInput.val()) {
                pickerInput.data("hint", $this.text());
                pickerInput.addClass("hinted")
                    .val(pickerInput.data("hint"))
                    .focus(function() {clearHint($(this));})
                    .blur(function() {resetHint($(this));});
                $this.closest("form").submit(function() {clearHint(pickerInput); pickerInput = 0;});
            }
        });
        
        $('#@ViewData.TemplateInfo.GetFullHtmlFieldId("ScheduledPublishDate")').datepicker({ showAnim: ""}).focus(function () { $('#@ViewData.TemplateInfo.GetFullHtmlFieldId("Command_PublishLater")').attr("checked", "checked") });
        $('#@ViewData.TemplateInfo.GetFullHtmlFieldId("ScheduledPublishTime")').timepicker({ stepMinute: 5}).focus(function () { $('#@ViewData.TemplateInfo.GetFullHtmlFieldId("Command_PublishLater")').attr("checked", "checked") });
    })
//]]>
</script>
}

}